package com.zwd.deep.controller;

import com.zwd.deep.common.RequestResult;
import com.zwd.deep.entity.vo.TaskVo;
import com.zwd.deep.service.TaskService;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 任务管理
 * @author zwd
 */
@RestController
@RequestMapping("/tasks")
@AllArgsConstructor
@Slf4j
@Validated
public class TaskController {

    private final TaskService taskService;

    /**
     * 创建任务
     * @param file 图片
     * @return 任务id
     */
    @PostMapping("/create")
    public RequestResult<String> create(@NotNull(message = "图片不能为空") @RequestBody MultipartFile file) {
        String taskId = taskService.createTask(file);
        return RequestResult.success(taskId);
    }

    /**
     * 查询结果
     * @param taskId 任务id
     * @return 结果
    @GetMapping("get")
    public RequestResult<String> get(@RequestParam("taskId") String taskId) {
        String result = taskService.getByTaskId(taskId);
        return RequestResult.success(result);
    }*/

    /**
     * 查询历史任务
     * @return 历史任务
     */
    @GetMapping("getHistory")
    public RequestResult<List<TaskVo>> getById() {
        List<TaskVo> result = taskService.getHistory();
        return RequestResult.success(result);
    }

}
